package fms.core;

import fms.acarsMsgProcessUtil.DownLinkDatagramHeader;
import fms.acarsMsgProcessUtil.RawDatagram;
import fms.util.DateUtil;
import fms.util.SysConstants;
import fms.xml.AutoPosRequestXML;
import fms.webservice.Request;
import fms.webservice.XmlUtil;
import org.apache.log4j.Logger;

public class DownRequestAutoPos {
    private Logger logger = Logger.getLogger(DownRequestAutoPos.class);
    public Request parse(String msg) {
        logger.debug("[报文解析] 开始进行‘飞机自动下发航路点请求报文’报文解析...");
        Request request = new Request();
        request.setServiceType( String.valueOf( ServiceType.AutoPosRequest.ordinal()));
        request.setVersion("1.0");
        AutoPosRequestXML autoPosRequestXML = new AutoPosRequestXML();
        DownLinkDatagramHeader msgHeader = null;
        try {
            msgHeader = DownLinkDatagramHeader.Parse(RawDatagram.GetHeader(msg));
        } catch (Exception e) {
            logger.error("解析报文头出错：" + "\r\n" + e.getMessage());
        }
        autoPosRequestXML.setFlightID(msgHeader.getFi().toString());
        autoPosRequestXML.setAircraftid(msgHeader.getAn());
        autoPosRequestXML.setRequestdate(DateUtil.getCurUTCtime(SysConstants.FORMAT_DATETIME_FULL));
        request.setRequestXML( XmlUtil.marshallAutoPosRequest(autoPosRequestXML) );
		return request;
	}
}